﻿using System;
using System.Buffers;

namespace eNets.CBK.Pipe;

partial class StandardPipe<T>
{
    sealed class StandardPipeReader : IPipeReader<T>
    {
        public StandardPipeReader(StandardPipe<T> pipe)
        {
            this.pipe = pipe;
        }

        private StandardPipe<T> pipe;

        public long ReadableLength
        {
            get { return this.pipe.buffer.ReadableLength; }
        }

        public void AddListener(Action listener)
        {
            this.pipe.AddListener(listener);
        }

        public void RcvAsync()
        {
            this.pipe.RcvAsync();
        }
        
        public ReadOnlySequence<T> GetReadableSequence()
        {
            return this.pipe.buffer.GetReadableSequence();
        }

        public void ReaderAdvanceTo(SequencePosition consumed)
        {
            this.pipe.buffer.ReaderAdvanceTo(consumed);
        }

        public void ReaderAdvanceTo(SequencePosition consumed, SequencePosition examined)
        {
            this.pipe.buffer.ReaderAdvanceTo(consumed, examined);
        }
        
        public void Flush()
        {
            this.pipe.ReaderFlush();
        }
    }
}